package com.youbang.bsMgr.role.service;

import com.youbang.base.service.BaseServiceImpl;
import com.youbang.bsMgr.role.dao.RoleDao;
import com.youbang.bsMgr.role.model.RoleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServiceImpl extends BaseServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;

    @Override
    public List<RoleEntity> GetAllRole(Integer pageSize,Integer startIndex, Integer pageIndex,String searchRoleName) {

        try {
            return roleDao.GetAllRole(pageSize,startIndex,pageIndex,searchRoleName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ArrayList<RoleEntity>();
    }

    /**
     * 新增
     * @param roleEntity
     * @return
     */
    @Override
    public int InsertRole(RoleEntity roleEntity) {
        int result = 0;
        try {
            result = roleDao.insert(roleEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /***
     * 查看详情
     * @param id
     * @return
     */
    @Override
    public RoleEntity selectByPrimaryKey(int id) {
        RoleEntity roleEntity = new RoleEntity();
        try {
            roleEntity = roleDao.selectByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return roleEntity;
    }

    @Override
    public int updateByPrimaryKey(RoleEntity record) {
        int result=0 ;
        try {
            result = roleDao.updateByPrimaryKey(record);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(int id) {
        int result=0 ;
        try {
            result = roleDao.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int GetAllRoleCout(String searchRoleName) {
        int result=0 ;
        try {
            result = roleDao.GetAllRoleCout(searchRoleName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
